package com.quo.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.quo.dto.ProductPlanDto;
import com.quo.dto.ProductsPlanDto;
import com.quo.dto.QuoDto;
import com.quo.dto.QuoInfo;
import com.quo.dto.QuotesDto;
import com.quo.entity.QuoDetail;
import com.quo.entity.Quote;
import com.quo.entity.QuoteDetail;
import com.quo.mapper.QuoteMapper;
import com.quo.service.QuoteService;

import org.apache.ibatis.session.SqlSession;

/** 

* @author zhoumin

*/
@Service("quoteService")
public class QuoteServiceImpl implements QuoteService {
	
	@Autowired
	private QuoteMapper qMapper;

	@Override
	public Long[] getPidsByQuoteDetail() {
		// TODO Auto-generated method stub
		return qMapper.getPidsByQuoteDetail();
	}

	@Override
	public List<QuotesDto> getQuoteList() {
		// TODO Auto-generated method stub
		return qMapper.getQuoteList();
	}

	@Override
	public QuoDto getQuoDto(Long qid) {
		// TODO Auto-generated method stub
		return qMapper.getQuoDto(qid);
	}
	
	@Override
	public List<QuoDetail> getQuoDetailList(Long qid) {
		// TODO Auto-generated method stub
		return qMapper.getQuoDetailList(qid);
	}

	//添加新报价单
	@Override
	public void addQuoInfo(Quote quote, List<QuoteDetail> quoteDetailList) {
		SimpleDateFormat sdfy = new SimpleDateFormat("yyyy-MM-dd");
		quote.setQdate(sdfy.format(new Date()));
		quote.setQsid(1);
		qMapper.addQuote(quote);
		System.out.println(quote);

			for(QuoteDetail qd : quoteDetailList) {
				qd.setQid(quote.getQid());
				qMapper.addQuoteDetail(qd);
			}
		
			/*System.out.println("11111111111"+quoteDetailList);
			qMapper.addAllQuoteDetail(quoteDetailList);*/
		
		
	}	

	//查询自己创建的报价单
	@Override
	public List<QuotesDto> getQuoteListForSelf(Integer eno) {
		// TODO Auto-generated method stub
		return qMapper.getQuoteListForSelf(eno);
	}

	//删除报价单
	@Override
	public void delQuoteInfo(Long qid) {
		qMapper.delQuoteDetail(qid);
		qMapper.delQuote(qid);
		
	}

	//获取特定报价单信息（个人）
	@Override
	public QuoDto getQuoDtoForSelf(Long qid, Integer eno) {
		// TODO Auto-generated method stub
		return qMapper.getQuoDtoForSelf(qid,eno);
	}

	@Override
	public List<QuotesDto> selectByQids(Long[] qids) {
		// TODO Auto-generated method stub
		return qMapper.selectByQids(qids);
	}

	@Override
	public List<Quote> getQuotePrint() {
		// TODO Auto-generated method stub
		return qMapper.getQuotePrint();
	}

	//获取所有待一级审核报价单信息
	@Override
	public List<QuotesDto> getQListForFirstExamine() {
		// TODO Auto-generated method stub
		return qMapper.getQListForFirstExamine();
	}

	@Override
	public void setAllQuotePass(Long[] qids) {
		// TODO Auto-generated method stub
		qMapper.setAllQuotePass(qids);
	}

	@Override
	public void setAllQuoteDeny(Long[] qids) {
		// TODO Auto-generated method stub
		qMapper.setAllQuoteDeny(qids);
	}

	@Override
	public void setQuotePass(Long qid) {
		// TODO Auto-generated method stub
		qMapper.setQuotePass(qid);
	}

	@Override
	public void setQuoteDeny(Long qid) {
		// TODO Auto-generated method stub
		qMapper.setQuoteDeny(qid);
	}

	@Override
	public List<ProductsPlanDto> getQListForProduce() {
		// TODO Auto-generated method stub
		return qMapper.getQListForProduce();
	}

	@Override
	public ProductPlanDto getProductPlanDto(Long qid) {
		// TODO Auto-generated method stub
		return qMapper.getProductPlanDto(qid);
	}

	@Override
	public void setAllProductPlanPass(Long[] qids) {
		// TODO Auto-generated method stub
		qMapper.setAllProductPlanPass(qids);
	}

	@Override
	public void setAllProductPlanDeny(Long[] qids) {
		// TODO Auto-generated method stub
		qMapper.setAllProductPlanDeny(qids);
	}

	@Override
	public void setProductPlanPass(Long qid) {
		// TODO Auto-generated method stub
		qMapper.setProductPlanPass(qid);
	}

	@Override
	public void setProductPlanDeny(Long pid) {
		// TODO Auto-generated method stub
		qMapper.setProductPlanDeny(pid);
	}


}
